﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToRTR.Views.ExportToRTRTreeItem
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.ExportToRTR.Resources;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ExportToRTR.Views;

internal class ExportToRTRTreeItem : IExportToRTRTreeViewItem, INotifyPropertyChanged
{
  private readonly ObservableCollection<IExportToRTRTreeViewItem> _children = new ObservableCollection<IExportToRTRTreeViewItem>();

  public event PropertyChangedEventHandler PropertyChanged;

  public ExportToRTRTreeItem()
  {
  }

  public ExportToRTRTreeItem(
    string name,
    ITxObject obj,
    ObservableCollection<IExportToRTRTreeViewItem> childrenItems,
    BitmapImage img,
    ObservableCollection<string> exportToRTRRoadMapConnectionOptions,
    IApExportToRTROperationData exportToRTROperationData = null)
  {
    this.ExportToRTRName = name;
    this.ExportToRTRObject = obj;
    this.ExportToRTRObjectIcon = img;
    this.ExportToRTRLocationData = exportToRTROperationData as CApExportToRTRLocationData;
    this.ExportToRTROperationData = exportToRTROperationData;
    this.ExportToRTRRoadMapConnectionOptions = exportToRTRRoadMapConnectionOptions;
    if (this.ExportToRTROperationData != null)
      this.ExportToRTROperationData.OperationChanged += new OnOperationChanged(this.OnOperationDataChanged);
    this._children = childrenItems != null ? childrenItems : new ObservableCollection<IExportToRTRTreeViewItem>();
    this.OnOperationDataChanged();
  }

  internal void OnOperationDataChanged()
  {
    this.UpateOperationData();
    this.OnPropertyChanges("ExportToRTRRoadMapConnectionText");
    this.OnPropertyChanges("ExportToRTRStatus");
    this.OnPropertyChanges("ObjectToolTip");
  }

  private void UpateOperationData()
  {
    if (this.ExportToRTRLocationData != null)
    {
      CApExportToRTRLocationData toRtrLocationData1 = this.ExportToRTRLocationData;
      if ((toRtrLocationData1 != null ? (toRtrLocationData1.ConnectionType == CApExportToRTRLocationData.ExportToRTRLocationDataConnectionType.CONNECTION_TYPE_TO_NEXT ? 1 : 0) : 0) != 0)
      {
        this.ExportToRTRRoadMapConnectionText = ExportToRTRStringTable.TREE_ROADMAP_CONNECTION_CONNECTED_TO_NEXT;
      }
      else
      {
        CApExportToRTRLocationData toRtrLocationData2 = this.ExportToRTRLocationData;
        this.ExportToRTRRoadMapConnectionText = (toRtrLocationData2 != null ? (toRtrLocationData2.ConnectionType == CApExportToRTRLocationData.ExportToRTRLocationDataConnectionType.CONNECTION_TYPE_TO_ALL ? 1 : 0) : 0) == 0 ? string.Empty : ExportToRTRStringTable.TREE_ROADMAP_CONNECTION_CONNECTED_TO_ALL;
      }
    }
    if (this.ExportToRTROperationData == null)
      return;
    IApExportToRTROperationData rtrOperationData1 = this.ExportToRTROperationData;
    if ((rtrOperationData1 != null ? (rtrOperationData1.IssueSevirity == CApExportToRTRStatusManager.Severity.Ok ? 1 : 0) : 0) != 0)
    {
      this.ExportToRTRStatus = ExportToRTRTreeViewStatusType.TREE_VIEW_STATUS_TYPE_OK;
    }
    else
    {
      IApExportToRTROperationData rtrOperationData2 = this.ExportToRTROperationData;
      if ((rtrOperationData2 != null ? (rtrOperationData2.IssueSevirity == CApExportToRTRStatusManager.Severity.Warning ? 1 : 0) : 0) != 0)
      {
        this.ExportToRTRStatus = ExportToRTRTreeViewStatusType.TREE_VIEW_STATUS_TYPE_WARNING;
      }
      else
      {
        IApExportToRTROperationData rtrOperationData3 = this.ExportToRTROperationData;
        if ((rtrOperationData3 != null ? (rtrOperationData3.IssueSevirity == CApExportToRTRStatusManager.Severity.Error ? 1 : 0) : 0) != 0)
          this.ExportToRTRStatus = ExportToRTRTreeViewStatusType.TREE_VIEW_STATUS_TYPE_ERROR;
      }
    }
    this.ObjectToolTip = this.ExportToRTROperationData?.IssueMessage != null ? this.ExportToRTROperationData?.IssueMessage : "✔";
  }

  public string ExportToRTRName { get; set; }

  public string ObjectToolTip { get; set; } = string.Empty;

  public BitmapImage ExportToRTRObjectIcon { get; set; }

  public ITxObject ExportToRTRObject { get; set; }

  internal CApExportToRTRLocationData ExportToRTRLocationData { get; set; }

  internal IApExportToRTROperationData ExportToRTROperationData { get; set; }

  public string ExportToRTRRoadMapConnectionText { get; set; } = string.Empty;

  public ExportToRTRTreeViewStatusType ExportToRTRStatus { get; set; }

  public ObservableCollection<IExportToRTRTreeViewItem> Children => this._children;

  public ObservableCollection<string> ExportToRTRRoadMapConnectionOptions { get; set; }

  public override bool Equals(object obj)
  {
    IExportToRTRTreeViewItem toRtrTreeViewItem = obj as IExportToRTRTreeViewItem;
    ITxObject itxObject = obj as ITxObject;
    if (toRtrTreeViewItem != null)
      return toRtrTreeViewItem.ExportToRTRObject.Id.Equals(this.ExportToRTRObject.Id);
    return itxObject != null && itxObject.Id.Equals(this.ExportToRTRObject.Id);
  }

  protected virtual void OnPropertyChanges(string propertyName)
  {
    PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
    if (propertyChanged == null)
      return;
    propertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
  }
}
